﻿using System;
using System.Xml;
using Autodesk.Revit.DB;
using YArchitech.Revit;
using YJKOpeningCommon.DataEnum;
using YJKOpeningCommon.Public;

namespace YJKOpeningCommon.DbOpening
{
	public class DbEquipRectFloorOpening : DbFamilyOpening
	{
		public override bool CreateOpeningFamilyInstance(ViewScene ViewScene, out Element elem3D, out Element elem2D)
		{
			elem2D = null;
			elem3D = null;
			return true;
		}

		public override bool CreateOpeningPreviewInstance(out Element elemPreview, PreViewScene preViewScene)
		{
			elemPreview = null;
			return true;
		}

		public override bool IsNeedCreateFamily()
		{
			return false;
		}

		public override bool Equals(object obj)
		{
			return base.Equals(obj);
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		public override void AddSharedParameters(Element elem)
		{
			Transaction transaction = new Transaction(elem.Document, "AddSharedParameter");
			try
			{
				transaction.Start();
				base.AddSharedParameters(elem);
				Parameter parameter = elem.GetParameter(DbOpeningBase.m_strSharedParaOpeningMajor);
				if (parameter != null && StrSpecialityObj.m_strSpecialityObj.GetLength(0) > (int)this.m_eSpeciality)
				{
					parameter.Set(StrSpecialityObj.m_strSpecialityObj[(int)this.m_eSpeciality]);
				}
				parameter = elem.GetParameter(DbOpeningBase.m_strSharedParaOpeningSize);
				if (parameter != null)
				{
					string openingSize = this.GetOpeningSize(false);
					parameter.Set(openingSize);
				}
				transaction.Commit();
			}
			catch
			{
				transaction.RollBack();
			}
		}

		public override bool Export2XmlNode(XmlElement xmlNode)
		{
			bool result;
			try
			{
				if (!base.Export2XmlNode(xmlNode))
				{
					result = false;
				}
				else
				{
					result = true;
				}
			}
			catch
			{
				xmlNode = null;
				result = false;
			}
			return result;
		}

		public override bool ImportByXmlNode(XmlNode xmlNode)
		{
			try
			{
				if (!base.ImportByXmlNode(xmlNode))
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			return true;
		}
	}
}
